package org.toycode.logindemo.application.tapestry.util;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import org.apache.tapestry5.OptionGroupModel;
import org.apache.tapestry5.OptionModel;
import org.apache.tapestry5.internal.OptionModelImpl;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
import org.apache.tapestry5.util.AbstractSelectModel;

/**
 * A simple tapestry5 select model implementation.
 *
 * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
 * @version 1.0.0.0, Aug 27, 2009
 */
public class SimpleSelectModel extends AbstractSelectModel
        implements Serializable {

    private static final long serialVersionUID = 1L;
    private final List<OptionModel> options = CollectionFactory.newList();

    public SimpleSelectModel(final Map<String, String> options) {
        for (final Map.Entry<String, String> e : options.entrySet()) {
            final OptionModel om = 
                    new OptionModelImpl(e.getKey(), e.getValue());
            this.options.add(om);
        }
    }

    /**
     * Returns <code>null</code>.
     */
    public List<OptionGroupModel> getOptionGroups() {
        return null;
    }

    /**
     * Returns the options initialized by constructor.
     */
    public List<OptionModel> getOptions() {
        return options;
    }
}
